/*
 * music.c
 *
 *  Created on: Apr 16, 2015
 *      Author: mxw
 */
#include "S3C2440addr.h"
#include <timer.h>
#include <UartDrv.h>

void on_time_out_mute(unsigned short tid);
void on_time_out_sing(unsigned short tid);
extern void set_led_by_low_4bit(unsigned char info);


struct Music_t {
    char c1;
    char c2;
    char* geci;
};

struct Music_t myMus_OnlyCareYou[] = {
    {0x16, 0x4, "如"},
    {0x16, 0x4, "果"},
    {0x16, 0x4, "没"},
    {0x15, 0xC4, "有"},
    {0x16, 0x8, "遇"},
    {0x16, 0x84, "见"},
    {0x6, 0x84, "你,"},
    {0x16, 0xA0, 0},
    {0x16, 0xC4, "我"},
    {0x16, 0xC4, "将"},
    {0x16, 0xC4, "会"},
    {0x16, 0x84, "是"},
    {0x16, 0x8, "在"},
    {0x16, 0xC4, "哪"},
    {0x6, 0x84, "里?"},
    {0x16, 0xA0, 0},
    {0x17, 0x44, "日"},
    {0x17, 0x44, "子"},
    {0x17, 0x44, "过"},
    {0x16, 0xC4, "得"},
    {0x17, 0x88, "怎"},
    {0x17, 0x44, "么"},
    {0x6, 0x84, "样?"},
    {0x16, 0xA0, 0},
    {0x16, 0xC4, "人"},
    {0x16, 0xC4, "生"},
    {0x16, 0xC4, "是"},
    {0x17, 0x44, "否"},
    {0x6, 0xC4, "要"},
    {0x16, 0x88, 0},
    {0x16, 0x4, "珍"},
    {0x15, 0xE0, "惜?"},
    {0x16, 0x4, "也"},
    {0x16, 0x4, "许"},
    {0x16, 0x4, "认"},
    {0x15, 0xC4, "识"},
    {0x16, 0x8, "某"},
    {0x16, 0x84, "一"},
    {0x6, 0x84, "人,"},
    {0x16, 0xA0, 0},
    {0x16, 0xC4, "过"},
    {0x16, 0xC4, "着"},
    {0x16, 0xC4, "平"},
    {0x16, 0x84, "凡"},
    {0x16, 0x8, "的"},
    {0x16, 0x84, "日"},
    {0x6, 0xC4, "子,"},
    {0x16, 0xA0, 0},
    {0x17, 0x44, "不"},
    {0x17, 0x48, "知"},
    {0x16, 0xC4, "道"},
    {0x17, 0x88, "会"},
    {0x17, 0x44, "不"},
    {0x6, 0x84, "会,"},
    {0x16, 0xA0, 0},
    {0x16, 0xC4, "也"},
    {0x16, 0xC4, "有"},
    {0x16, 0xC4, "爱"},
    {0x16, 0x84, "情"},
    {0x16, 0xC8, "甜"},
    {0x17, 0xC8, "如"},
    {0x7, 0xA0, "蜜,"},
    {0x17, 0x88, 0},
    {0x16, 0x88, "任"},
    {0x17, 0x48, "时"},
    {0x17, 0x88, "光"},
    {0x17, 0xC8, "匆"},
    {0x17, 0x88, "匆"},
    {0x17, 0x48, "流"},
    {0x17, 0x8, "去,"},
    {0x17, 0x48, "我"},
    {0x17, 0x8, "只"},
    {0x16, 0xC8, "在"},
    {0x16, 0x88, "乎"},
    {0x16, 0xE0, "你,"},
    {0x10, 0x18, 0},
    {0x17, 0x44, "心"},
    {0x17, 0x84, "甘"},
    {0x17, 0xC8, "情"},
    {0x17, 0x88, "愿"},
    {0x17, 0x48, "感"},
    {0x17, 0x8, "染"},
    {0x17, 0x48, "你"},
    {0x17, 0x8, "的"},
    {0x6, 0x8, "气"},
    {0x16, 0x88, 0},
    {0x6, 0xD0, "息,"},
    {0x16, 0xE0, 0},
    {0x10, 0x8, 0},
    {0x16, 0xC4, "人"},
    {0x16, 0x84, "生"},
    {0x16, 0xC8, "几"},
    {0x7, 0x48, "何"},
    {0x17, 0x50, 0},
    {0x10, 0x8, 0},
    {0x17, 0x50, "能"},
    {0x17, 0x88, "够"},
    {0x17, 0xC8, "得"},
    {0x17, 0x48, "到"},
    {0x7, 0x88, "知"},
    {0x17, 0x48, 0},
    {0x17, 0x58, "已,"},
    {0x16, 0xC4, "失"},
    {0x16, 0xC4, "去"},
    {0x18, 0x8, "生"},
    {0x17, 0xC8, "命"},
    {0x17, 0x88, "力"},
    {0x17, 0x44, "量"},
    {0x8, 0x4, 0},
    {0x18, 0x8, 0},
    {0x17, 0xC8, "也"},
    {0x17, 0x88, "不"},
    {0x17, 0x48, "可"},
    {0x7, 0x90, "惜,"},
    {0x17, 0xA0, 0},
    {0x17, 0xC8, "所"},
    {0x7, 0x84, "以"},
    {0x17, 0x44, 0},
    {0x17, 0x50, "我"},
    {0x17, 0x48, "求"},
    {0x17, 0x88, "求"},
    {0x17, 0xD8, "你,"},
    {0x17, 0x48, "别"},
    {0x18, 0x88, "让"},
    {0x18, 0x48, "我"},
    {0x7, 0xC4, "离"},
    {0x17, 0x84, 0},
    {0x17, 0x48, "开"},
    {0x16, 0xE0, "你,"},
    {0x10, 0x8, 0},
    {0x16, 0x88, "除"},
    {0x17, 0x48, "了"},
    {0x17, 0xC8, "你"},
    {0x18, 0x48, "我"},
    {0x18, 0x84, "不"},
    {0x7, 0xC4, "能"},
    {0x17, 0xC4, 0},
    {0x17, 0x84, "感"},
    {0x17, 0x48, "到"},
    {0x16, 0xC8, "一"},
    {0x17, 0x48, "丝"},
    {0x17, 0x44, "丝"},
    {0x7, 0x88, "情"},
    {0x17, 0x44, 0},
    {0x17, 0x60, "意."},
};

struct Music_t myMus_YellowHill[] = {
    {0x15, 0xC8, "我"},
    {0x15, 0xC8, "家"},
    {0x15, 0xC8, "住"},
    {0x15, 0xC8, "在"},
    {0x16, 0x88, "黄"},
    {0x15, 0xC8, "土"},
    {0x16, 0x90, "高"},
    {0x6, 0x98, "坡,"},
    {0x6, 0x44, 0},
    {0x6, 0x4, 0},
    {0x15, 0xE0, 0},
    {0x16, 0x48, "大"},
    {0x16, 0x50, "风"},
    {0x16, 0x8, "从"},
    {0x15, 0xC8, "坡"},
    {0x15, 0xC8, "上"},
    {0x15, 0x88, "刮"},
    {0x15, 0xF0, "过,"},
    {0x10, 0x8, 0},
    {0x15, 0xC8, "不"},
    {0x15, 0xD0, "管"},
    {0x15, 0xC8, "是"},
    {0x16, 0x88, "西"},
    {0x16, 0x88, "北"},
    {0x16, 0x90, "风"},
    {0x16, 0x8C, "还"},
    {0x16, 0x84, "是"},
    {0x15, 0xC8, "东"},
    {0x16, 0x88, "南"},
    {0x6, 0x8C, "风,"},
    {0x7, 0x50, 0},
    {0x5, 0x88, 0},
    {0x15, 0x48, 0},
    {0x15, 0xC, "都"},
    {0x14, 0xC4, "是"},
    {0x15, 0x8, "我"},
    {0x15, 0xC8, "的"},
    {0x15, 0xD0, "歌"},
    {0x15, 0x8, "我"},
    {0x5, 0x44, "的"},
    {0x15, 0x10, 0},
    {0x14, 0xE0, "歌."},
    {0x10, 0x10, 0},
    {0x15, 0xC8, "我"},
    {0x15, 0xC8, "家"},
    {0x15, 0xC8, "住"},
    {0x15, 0xC8, "在"},
    {0x16, 0x88, "黄"},
    {0x15, 0xC8, "土"},
    {0x16, 0x90, "高"},
    {0x6, 0x98, "坡,"},
    {0x6, 0x44, 0},
    {0x6, 0x4, 0},
    {0x15, 0xE0, 0},
    {0x16, 0x48, "大"},
    {0x16, 0x50, "风"},
    {0x16, 0x8, "从"},
    {0x15, 0xC8, "坡"},
    {0x15, 0xC8, "上"},
    {0x15, 0x88, "刮"},
    {0x15, 0xE0, "过,"},
    {0x10, 0x20, 0},
    {0x15, 0xC8, "不"},
    {0x15, 0xD0, "管"},
    {0x15, 0xC8, "是"},
    {0x16, 0x88, "西"},
    {0x16, 0x88, "北"},
    {0x16, 0x90, "风"},
    {0x16, 0x8C, "还"},
    {0x16, 0x84, "是"},
    {0x15, 0xC8, "东"},
    {0x16, 0x88, "南"},
    {0x6, 0x8C, "风,"},
    {0x7, 0x50, 0},
    {0x5, 0x88, 0},
    {0x15, 0x48, 0},
    {0x15, 0xC, "都"},
    {0x14, 0xC4, "是"},
    {0x15, 0x8, "我"},
    {0x15, 0xC8, "的"},
    {0x15, 0xD0, "歌"},
    {0x15, 0x8, "我"},
    {0x5, 0x44, "的"},
    {0x15, 0x10, 0},
    {0x14, 0xE0, "歌."},
    {0x10, 0x20, 0},
    {0x16, 0x48, "不"},
    {0x16, 0x50, "管"},
    {0x16, 0x10, "过"},
    {0x15, 0xC8, "去"},
    {0x10, 0x8, 0},
    {0x15, 0x88, "了"},
    {0x16, 0x4C, "多"},
    {0x16, 0x44, "少"},
    {0x6, 0x48, "岁"},
    {0x16, 0x8, 0},
    {0x15, 0xE0, "月,"},
    {0x16, 0x4C, "祖"},
    {0x16, 0x44, "祖"},
    {0x16, 0x48, "辈"},
    {0x16, 0x8, "辈"},
    {0x5, 0xCC, "留"},
    {0x14, 0xC4, 0},
    {0x14, 0xD0, "下"},
    {0x15, 0x30, "我,"},
    {0x10, 0x10, 0},
    {0x16, 0x48, "留"},
    {0x16, 0x50, "下"},
    {0x16, 0x8, "我"},
    {0x15, 0xC8, "一"},
    {0x15, 0xC8, "望"},
    {0x15, 0x88, "无"},
    {0x15, 0xC8, "际"},
    {0x16, 0x50, "唱"},
    {0x6, 0x48, "着"},
    {0x16, 0x8, 0},
    {0x15, 0xE0, "歌,"},
    {0x15, 0xCC, "还"},
    {0x15, 0xC4, "有"},
    {0x15, 0xC8, "身"},
    {0x16, 0x48, "边"},
    {0x15, 0xC8, "这"},
    {0x15, 0x88, "条"},
    {0x5, 0x48, "黄"},
    {0x14, 0xD0, 0},
    {0x15, 0xB0, "河"},
    {0x5, 0xD0, "噢"},
    {0x6, 0x60, 0},
    {0x6, 0xCC, 0},
    {0x7, 0x44, 0},
    {0x6, 0xC8, 0},
    {0x16, 0xB0, 0},
    {0x10, 0x8, 0},
    {0x17, 0x48, "我"},
    {0x17, 0x48, "家"},
    {0x17, 0x48, "住"},
    {0x17, 0x8, "在"},
    {0x16, 0xC8, "黄"},
    {0x16, 0x88, "土"},
    {0x16, 0xD0, "高"},
    {0x6, 0xCC, "坡,"},
    {0x7, 0x44, 0},
    {0x6, 0x58, 0},
    {0x6, 0x8, 0},
    {0x15, 0xD0, 0},
    {0x17, 0x48, "四"},
    {0x17, 0x48, "季"},
    {0x17, 0x48, "风"},
    {0x17, 0x8, "从"},
    {0x16, 0xC8, "坡"},
    {0x16, 0x88, "上"},
    {0x16, 0xD0, "刮"},
    {0x6, 0xC8, "过,"},
    {0x7, 0x44, 0},
    {0x6, 0x58, 0},
    {0x6, 0x8, 0},
    {0x15, 0xD0, 0},
    {0x15, 0xC8, "不"},
    {0x15, 0xD0, "管"},
    {0x15, 0xC8, "是"},
    {0x16, 0x90, "八"},
    {0x16, 0x8C, "百"},
    {0x16, 0x84, "年"},
    {0x16, 0x8C, "还"},
    {0x16, 0x84, "是"},
    {0x15, 0xC8, "一"},
    {0x16, 0x88, "万"},
    {0x6, 0x8C, "年,"},
    {0x7, 0x44, 0},
    {0x5, 0x88, 0},
    {0x15, 0x48, 0},
    {0x15, 0xC, "都"},
    {0x14, 0xC4, "是"},
    {0x15, 0x8, "我"},
    {0x15, 0xC8, "的"},
    {0x15, 0xD0, "歌"},
    {0x15, 0x8, "我"},
    {0x5, 0x44, "的"},
    {0x15, 0x4, 0},
    {0x16, 0xB0, "歌."},
    {0x10, 0x10, 0},
    {0x5, 0x10, "噢"},
    {0x15, 0xB0, 0},
    {0x5, 0xD0, "噢~"},
    {0x6, 0x60, 0},
    {0x6, 0xCC, 0},
    {0x7, 0x44, 0},
    {0x6, 0xC8, 0},
    {0x16, 0xE0, 0},
    {0x10, 0x10, 0},
};

struct Music_t myMus_HappySlave[] = {
    {0x15, 0x10, "太"},
    {0x5, 0xC8, "阳"},
    {0x16, 0x4, 0},
    {0x5, 0x84, "阿!"},
    {0x15, 0xE0, 0},
    {0x16, 0xC, "霞"},
    {0x16, 0x84, "光"},
    {0x6, 0xD0, "万"},
    {0x7, 0x44, 0},
    {0x6, 0x84, 0},
    {0x16, 0xC4, 0},
    {0x16, 0x20, "丈,"},
    {0x16, 0x90, "雄"},
    {0x5, 0x8, "鹰"},
    {0x5, 0x84, 0},
    {0x16, 0x4, 0},
    {0x5, 0xCC, "啊,"},
    {0x16, 0x8, 0},
    {0x15, 0x8C, "展"},
    {0x15, 0xC4, "翅"},
    {0x5, 0x8, 0},
    {0x14, 0xC8, "飞"},
    {0x15, 0x20, "翔."},
    {0x16, 0xD8, "高"},
    {0x16, 0xC8, "原"},
    {0x6, 0x88, "春"},
    {0x6, 0xC4, 0},
    {0x16, 0x84, 0},
    {0x16, 0x10, "光"},
    {0x17, 0x10, "无"},
    {0x6, 0xC4, "限"},
    {0x7, 0x4, 0},
    {0x6, 0x84, 0},
    {0x16, 0xC4, 0},
    {0x6, 0x18, "好,"},
    {0x16, 0x88, 0},
    {0x15, 0xCC, "叫"},
    {0x16, 0x4, "我"},
    {0x16, 0x88, "怎"},
    {0x16, 0xC8, "能"},
    {0x6, 0x8, "不"},
    {0x16, 0x88, 0},
    {0x5, 0x8, "歌"},
    {0x15, 0x88, 0},
    {0x15, 0xE0, "唱."},
    {0x16, 0xD8, "高"},
    {0x16, 0xC8, "原"},
    {0x6, 0x88, "春"},
    {0x6, 0xC4, 0},
    {0x16, 0x84, 0},
    {0x16, 0x10, "光"},
    {0x17, 0x8, "无"},
    {0x6, 0xC4, "限"},
    {0x7, 0x4, 0},
    {0x6, 0x84, 0},
    {0x16, 0xC4, 0},
    {0x6, 0x18, "好,"},
    {0x16, 0x88, 0},
    {0x15, 0xCC, "叫"},
    {0x16, 0x4, "我"},
    {0x16, 0x88, "怎"},
    {0x16, 0xC8, "能"},
    {0x6, 0x8, "不"},
    {0x5, 0xC4, 0},
    {0x15, 0x84, 0},
    {0x5, 0x8, "歌"},
    {0x14, 0xC8, 0},
    {0x15, 0x20, "唱."},
};


/*         c1                 c2
 *  0 0 0 0  0 0 0 0   0 0 0 0  0 0 0 0
 *        - -------------- ------------
 *        |      |_yingao       |___shichang
 *        |
 *        |_kongxi
 * */
void Buzzer_Freq_Set(unsigned int freq)
{
    rGPBCON &= ~3;          //set GPB0 as tout0, pwm output
    rGPBCON |= 2;

    rTCFG0 &= ~0xff;
    rTCFG0 |= 15;           //prescaler = 15+1
    rTCFG1 &= ~0xf;
    rTCFG1 |= 2;            //mux = 1/8
    //rTCNTB0 = (PCLK>>7)/freq;
    rTCNTB0 = freq;
    rTCMPB0 = rTCNTB0>>1;   // 50%
    rTCON &= ~0x1f;
    rTCON |= 0xb;           //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
    rTCON &= ~2;            //clear manual update bit
}
void Buzzer_Stop( void ){
    rGPBCON &= ~3;          //set GPB0 as output
    rGPBCON |= 1;
    rGPBDAT &= ~1;
}

//unsigned int freqTab[] = {
//        0,//静止符
//        200, 200, 200, 200, 200, 200, 200, //低二 1,2,3,4,5,6,7
//        131, 147, 165, 175, 196, 220, 247, //低一 1,2,3,4,5,6,7
//        262, 286, 330, 349, 392, 440, 494, //常音 1,2,3,4,5,6,7
//        523, 587, 659, 698, 784, 879, 987, //高一 1,2,3,4,5,6,7
//        1047, 1175, 1319, 1397, 1568, 1760, 1976, //高二 1,2,3,4,5,6,7
//};
unsigned int freqTab[] = {
        0,//静止符
        1953, 1953, 1953, 1953, 1953, 1953, 1953,   //低二 1,2,3,4,5,6,7
        2981, 2657, 2367, 2232, 1992, 1775, 1581,    //低一 1,2,3,4,5,6,7
        1490, 1365, 1183, 1119, 996, 887, 790,       //常音 1,2,3,4,5,6,7
        746, 665, 592, 559, 498, 444, 395,           //高一 1,2,3,4,5,6,7
        373, 332, 296, 279, 249, 221, 197           //高二 1,2,3,4,5,6,7
};

//BOARD BEEP
void mybeep(unsigned int freq, unsigned int ms) {
    Buzzer_Freq_Set(freq);
    //Delay(ms);
    Buzzer_Stop();
}

//shichangBase_Ms 表示1/64拍所用的毫秒数
void subPlay(char yingaoidx, char shichang, int kongxi, int shichangBase_Ms) {
    if (0 != yingaoidx) { //如果yingaoidx为0则表示静止符
        //real play 以指定时间长度,指定频率PWM播放
//        mybeep(freqTab[yingaoidx], shichang * shichangBase_Ms);
        if (kongxi) {
            //Delay(15);
        }
    } else {
        Buzzer_Stop();
        //Delay(shichang * shichangBase_Ms);
    }
    return;
}


int g_cur_idx = 0;
int g_end_idx = 0;

char g_yingaoIdx = 0;
char g_shichang = 0;
int g_kongxi = 0;


void play(struct Music_t* pmusHead, int eleCnt) {
    int idx = 0;
    while(idx < eleCnt) {
        int isum = ((pmusHead[idx].c1 << 8) | pmusHead[idx].c2);
        char yingaoIdx = ((isum >> 6) & 0x3F);
        char shichang = (isum & 0x3F);
        int kongxi = ((isum >> 12) & 0x1);
        if (0 != pmusHead[idx].geci) {
            //Uart_Printf("yingaoIdx=%d, shichang=%d, kongxi=%d, geci=%s\n",yingaoIdx, shichang, kongxi, pmusHead[idx].geci);
        } else {
            //Uart_Printf("yingaoIdx=%d, shichang=%d, kongxi=%d, geci=%s\n",yingaoIdx, shichang, kongxi, "null");
        }
        subPlay(yingaoIdx, shichang, kongxi, 40);
        ++idx;
    }
    return;
}

struct MusHead_t {
    struct Music_t* head;
    int             toneCnt;
    char*           name;
};

struct MusHead_t allMus[] = {
    {myMus_OnlyCareYou, sizeof(myMus_OnlyCareYou) / sizeof(struct Music_t), "我只在乎你"},
    {myMus_YellowHill, sizeof(myMus_YellowHill) / sizeof(struct Music_t), "黄土高坡"},
    {myMus_HappySlave, sizeof(myMus_HappySlave) / sizeof(struct Music_t), "翻身农奴把歌唱"},
};

#define ST_SING_STOP            (0)
#define ST_PRE_MUTE             (1)
#define ST_SINGING              (2)
static unsigned char _music_st = ST_SING_STOP;
static unsigned short _tid_mute = 0;
static unsigned short _tid_sing = 0;


int isum = 0;

void init_music() {
    _music_st = ST_SING_STOP;
    _tid_mute = get_new_timer(on_time_out_mute);
    _tid_sing = get_new_timer(on_time_out_sing);
}

void request_to_stop() {
    switch(_music_st) {
    case ST_SING_STOP:
        break;
    case ST_PRE_MUTE:
    case ST_SINGING:
        Buzzer_Stop();
        stop_timer(_tid_mute);
        stop_timer(_tid_sing);
        _music_st = ST_SING_STOP;
        break;
    default:
        ;
        break;
    }
}

void on_time_out_mute(unsigned short tid) {
    switch(_music_st) {
    case ST_SING_STOP:
        break;
    case ST_PRE_MUTE:
        stop_timer(_tid_mute);

        isum = ((myMus_OnlyCareYou[g_cur_idx].c1 << 8) | myMus_OnlyCareYou[g_cur_idx].c2);
        uart_print(myMus_OnlyCareYou[g_cur_idx].geci);
        ++g_cur_idx;

        g_yingaoIdx = ((isum >> 6) & 0x3F);
        g_shichang = (isum & 0x3F);
        g_kongxi = ((isum >> 12) & 0x1);
        Buzzer_Freq_Set(freqTab[(int)g_yingaoIdx]);
        set_led_by_low_4bit(g_yingaoIdx);
        start_timer(_tid_sing, g_shichang * 40);

        _music_st = ST_SINGING;

        if (g_cur_idx > g_end_idx) {
            _music_st = ST_SING_STOP;
        }
        break;
    case ST_SINGING:
        break;
    default:
        ;
        break;
    }
}

void on_time_out_sing(unsigned short tid) {
    switch(_music_st) {
    case ST_SING_STOP:
        break;
    case ST_PRE_MUTE:
        break;
    case ST_SINGING:
        stop_timer(_tid_sing);
        if (g_kongxi) {
            Buzzer_Stop();
            start_timer(_tid_mute, 20);
            _music_st = ST_PRE_MUTE;
        } else {
            isum = ((myMus_OnlyCareYou[g_cur_idx].c1 << 8) | myMus_OnlyCareYou[g_cur_idx].c2);
            uart_print(myMus_OnlyCareYou[g_cur_idx].geci);
            ++g_cur_idx;

            g_yingaoIdx = ((isum >> 6) & 0x3F);
            g_shichang = (isum & 0x3F);
            g_kongxi = ((isum >> 12) & 0x1);
            Buzzer_Freq_Set(freqTab[(int)g_yingaoIdx]);
            set_led_by_low_4bit(g_yingaoIdx);
            start_timer(_tid_sing, g_shichang * 40);

            if (g_cur_idx > g_end_idx) {
                _music_st = ST_SING_STOP;
            }
        }
        break;
    default:
        ;
        break;
    }
}

void new_muisc_go() {
    g_cur_idx = 0;
    g_end_idx = sizeof(myMus_OnlyCareYou) / sizeof(struct Music_t);

    isum = ((myMus_OnlyCareYou[g_cur_idx].c1 << 8) | myMus_OnlyCareYou[g_cur_idx].c2);
    uart_print(myMus_OnlyCareYou[g_cur_idx].geci);


    g_yingaoIdx = ((isum >> 6) & 0x3F);
    g_shichang = (isum & 0x3F);
    g_kongxi = ((isum >> 12) & 0x1);

    Buzzer_Freq_Set(freqTab[(int)g_yingaoIdx]);
    set_led_by_low_4bit(g_yingaoIdx);
    start_timer(_tid_sing, g_shichang * 40);

    ++g_cur_idx;
    _music_st = ST_SINGING;
}

void musicGo(void) {
    while(1)
    {
        unsigned char idx;
        int i = 0;
        int cnt = sizeof(allMus) / sizeof(struct MusHead_t);
        //Uart_Printf("\nPlease select music : \n");
        for(i=0; i < cnt; i++) {
            //Uart_Printf("%2d : %s\n", i, allMus[i].name);
        }
        idx = 1;//Uart_GetIntNum_GJ() ;
        if(idx < cnt)
        {
            play(allMus[idx].head, allMus[idx].toneCnt);
        }
    }

}
